using System;
using System.Collections.Generic;
using System.Text;

namespace org.ngwt.user.server.rpc.impl
{
    class CharVector
    {
        private int capacityIncrement;
        private char[] chars;
        private int size;

        public CharVector(int initialCapacity, int capacityIncrement) {
          //assert (initialCapacity >= 0);
          //assert (capacityIncrement >= 0);

          this.capacityIncrement = capacityIncrement;
          chars = new char[initialCapacity];
        }

        public void add(char ch) {
          if (size >= chars.Length) {
            int growBy = (capacityIncrement == 0) ? chars.Length * 2
                : capacityIncrement;
            char[] newChars = new char[(chars.Length + growBy)];
            Array.Copy(chars, 0, newChars, 0, size);
            chars = newChars;
          }

          chars[size++] = ch;
        }

        public char[] asArray() {
          return chars;
        }

        public char get(int index) {
         // assert (index < size);

          return chars[index];
        }

        public int getSize() {
          return size;
        }

        public void set(int index, char ch) {
          //assert (index >= 0 && index < size);

          chars[index] = ch;
          ++size;
        }
    }
}
